package com.graduation.vaccine.controller;

import com.graduation.vaccine.service.UserService;
import com.graduation.vaccine.vo.RegisterVo;
import com.graduation.vaccine.vo.RespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhaoJunYao
 * @since 2022-04-10
 */
@RestController
@RequestMapping("register")
@Slf4j
@Api(tags = "注册模块")
public class RegisterController {

    @Autowired
    private UserService userService;

    @PostMapping("/user")
    @ResponseBody
    @ApiOperation("用户注册")
    @Transactional(rollbackFor = Exception.class)
    public RespBean registerUser(@Valid @RequestBody RegisterVo registerVo){
        return userService.register(registerVo);
    }

//    @ApiOperation("部门注册")
//    @ResponseBody
//    @PostMapping("/company")
//    public RespBean registerCompany(@Valid @RequestBody CompanyRegisterVo registerCompanyVo){
//        return userService.registerComoany(registerCompanyVo);
//    }


    @PostMapping("/sendEmail")
    @ResponseBody
    @ApiOperation("发送验证码")
    public RespBean sendEmail(@Valid@RequestParam(name="email") String email){
        return userService.sendEmail(email);
    }
}
